﻿@{
    Customer cust = new Customer();
    cust.FName = UtilityManager.GetVal(Request["fname"]);
    cust.MName = UtilityManager.GetVal(Request["mname"]);
    cust.LName=UtilityManager.GetVal(Request["lname"]);
    cust.Bdate=UtilityManager.GetDateVal(Request["bdate"]);
    cust.HasDuplicate=Convert.ToInt32(Request["hasDup"]);
    cust.Region=UtilityManager.GetVal(Request["region"]); 
    cust.Country=UtilityManager.GetVal(Request["country"]);
    cust.CurrMailState=UtilityManager.GetVal(Request["state"]);
    cust.CurrMailZip=UtilityManager.GetVal(Request["zip"]);
    cust.IDNumber=UtilityManager.GetVal(Request["idNum"]);
    cust.IDType=UtilityManager.GetVal(Request["idType"]);
    cust.MobileNo=UtilityManager.GetVal(Request["mobileCC"]) +"|"+ UtilityManager.GetVal(Request["mobileAC"]) +"|"+ UtilityManager.GetVal(Request["mobilePNo"]);
    cust.LandLineNo=UtilityManager.GetVal(Request["landLineCC"]) +"|"+ UtilityManager.GetVal(Request["landLineAC"]) +"|"+ UtilityManager.GetVal(Request["landLinePNo"]);
   
    
     var query = CustomerManager.SearchCustomer2(cust);
      
      var data = string.Format("?fname={0}&mname={1}&lname={2}&bdate={3}&hasDup={4}",cust.FName,cust.MName,cust.LName,cust.Bdate,cust.HasDuplicate);
      var cols = new []{"FName","LName","CustomerStatus","CurrMailCountry","CurrMailState","CurrMailZip","Bdate","MobileNo","LandLineNo","IDType","Solicitor","ReferredBy"};
      var grid = new WebGrid(query,canSort:false,canPage:true,rowsPerPage:5,columnNames:cols,ajaxUpdateContainerId: "grid2");
       
}
<style>
    .fg-button{
        outline:0;
        marin:0 4 0 0;
        /*padding: .4em 1em;*/
        text-decoration:none !important;
        cursor:pointer;
        position:relative;
        text-align:center;
        zoom:1;
        width:100px;
        height:25px;
       
    }
    
</style>
<script>
    $(function(){
        
        $("#addCustomer").click(function(){
            $("#custSearchForm").attr("action","@Href("~/Customer/Index/main")");
            $("#custSearchForm").submit();
        });
        
        $('th a, tfoot a').live('click', function(){
            $(this).attr('href', '#grid-anchor');
        });
    });
</script>
<fieldset>
        <legend>Search Results</legend>
         <a name="grid-anchor"></a>   
        <div id="grid2">
            @functions{
                  static IHtmlString ShowBDate(string bdate){
                      return bdate!="01-01-1900"?new HtmlString(bdate):new HtmlString("");
                } 
                
                static IHtmlString ShowMobileNo(string mobileNo){
                     return mobileNo!="63"?new HtmlString(mobileNo):new HtmlString("");
                }
                
                static IHtmlString ShowLLNo(string llNo){
                     return llNo!="63"?new HtmlString(llNo):new HtmlString("");
                }
                static IHtmlString ShowReferror(string id){
                    var cust = CustomerManager.GetCustomer(id);
                    if(cust!=null){
                        return new HtmlString(cust.FName + " " + cust.LName);
                    }else{
                        return new HtmlString("");
                    }
                }
                static IHtmlString ShowIDType(string idType){
                    return idType=="default"?new HtmlString(""):new HtmlString(idType);
                }
                
           }
            @grid.GetHtml(
               tableStyle:"webgrid",
               alternatingRowStyle:"webgrid-alternating-row",
               headerStyle:"ui-widget-header",
               fillEmptyRows:true,
               columns:grid.Columns(
                      
                      grid.Column(
                      header:"",
                      format:@<a href="/Customer/Index/edit/@item.CustomerID">Edit</a>),
                     
                      grid.Column(
                      header:"",
                      format:@<a href="/Customer/Index/view/@item.CustomerID">View</a>),
                    
                       grid.Column(
                        columnName:"FName",
                        header:"First Name"
                      ),
                      grid.Column(
                         columnName:"LName",
                         header:"Last Name"
                      ),
                     grid.Column(
                         columnName:"CustomerStatus",
                         header:"Customer Status"
                      ),
                    grid.Column(
                         columnName:"CurrMailCountry",
                         header:"Country"
                      ),
                    
                      grid.Column(
                         columnName:"CurrMailState",
                         header:"State"
                      ),
                    
                      grid.Column(
                         columnName:"CurrMailZip",
                         header:"Zipcode"
                      ),
                      grid.Column(
                         columnName:"Bdate",
                         header:"Birthday",
                         format:@<text>@ShowBDate(item.Bdate.ToString("MM-dd-yyyy"))</text>
                      ),
                    
                      grid.Column(
                         columnName:"MobileNo",
                         header:"Mobile No",
                         format:@<text>@ShowMobileNo(item.MobileNo.ToString().Replace("|",""))</text>
                                            
                      ),
                    
                      grid.Column(
                         columnName:"LandLineNo",
                         header:"Land Line No",
                         format:@<text>@ShowLLNo(item.LandLineNo.ToString().Replace("|",""))</text>
                      ),
                    
                      grid.Column(
                         columnName:"IDType",
                         header:"ID Presented",
                         format:@<text>@ShowIDType(item.IDType.ToString())</text>
                      ),
                    
                      grid.Column(
                         columnName:"Solicitor",
                         header:"Solicitor"
                      ),
                    
                      grid.Column(
                         columnName:"ReferredBy",
                         header:"Referred By",
                         format:@<text>@ShowReferror(item.ReferredBy.ToString())</text>
                      )
                      
                    
                    
                      
               
              )
               
            )
        </div>
           </fieldset>
       <div id="buttons" >
        <p>
        <input class="fg-button ui-state-default ui-corner-all" type="button" name="addCustomer" id="addCustomer" value="Add Customer"/>    
        </p>
        
    </div>
    